# vip用户
Vqueue = []

# normal用户
Nqueue = []


def inQueue(name,type): # 入队
    if type == 'V':
        Vqueue.append(name)

    if type == 'N':
        Nqueue.append(name)


def queueHead(type): # 取队头
    if type == 'V':
        return Vqueue[0]

    if type == 'N':
        return Nqueue[0]


def outQueue(type): # 出队
    if type == 'V':
        if Vqueue:
            Vqueue.pop(0)
    if type == 'N':
        if Nqueue:
            Nqueue.pop(0)

if __name__ == '__main__':
    M = int(input())
    for i in range(M):
        op = input().split()
        if op[0] == 'IN':
            inQueue(op[1],op[2])

        if op[0] == 'OUT':
            outQueue(op[1])
    for i in range(len(Vqueue)):
        print(Vqueue[i])
    for i in range(len(Nqueue)):
        print(Nqueue[i])